<template>
    <div>
        <c-header :p-title="'分活动'+title">
            <div class="d-flex justify-content-end align-items-center">
                <button class="btn btn-sm btn-primary" @click="exportFile">导出最新全体参会人员</button>
                <button v-if="!no_return" type="button" class="btn btn-sm btn-info d-lg-block  m-l-sm"  @click="$router.go(-1)"><i class="fa fa-mail-reply m-r-sm"></i>返回</button>
                <btn-refresh class='m-l-sm' :p-data='init'></btn-refresh>
            </div>
        </c-header>
        <div class="row">
            <div class="col-lg-12">
                <div class="card">
                    <div class="card-body">
                        <div class="table-responsive"  v-if='list'>
                            <table class="vm table color-bordered-table base-bordered-table table-bordered table-hover">
                                <thead>
                                <tr class="nowrap">
                                    <!--<th>ID</th>-->
                                    <th>分活动主题</th>
                                    <th>地点</th>
                                    <th>开始时间</th>
                                    <th width="60">操作</th>
                                </tr>
                                </thead>
                                <tbody  v-show='list.length'>
                                <tr v-for="(item,key) in list">
                                    <!--<td>{{item.id}}</td>-->
                                    <td>{{item.title}}</td>
                                    <td>{{item.address}}</td>
                                    <td>{{item.start_at}}</td>
                                    <td class="no-h-bg">
                                        <div class="table-edit-group">
                                            <button class="btn btn-sm btn-info m-l-sm"  @click='lookAtDetail("customer",item)'>参会人员管理</button>
                                        </div>
                                    </td>
                                </tr>
                                </tbody>
                            </table>
                            <div  v-show='!list.length' class="text-center m-b-sm">
                                暂无数据！
                            </div>
                        </div>
                        <hr/>
                        <!--<footer class="panel-footer text-right">
                            <CPage :total="search.page_total"
                                   :current='search.page_current'
                                   :page-size='search.page_row'
                                   @on-change='pageCurrentChange'
                                   @on-page-size-change='pageRowChange'></CPage>
                        </footer>-->
                    </div>
                </div>
            </div>
        </div>
        <operate-detail ref="operate_detail"></operate-detail>
        <operate-save ref="operate_save" @on-change="initSubmit"></operate-save>
    </div>
</template>
<script>
    import serConference from '../../serves/api-conference'
    import serCustomer from '../../serves/api-customer'
    import operateDetail from './detail'
    import operateSave from './saveChild'
    const __page_key = 'conference.child.list';
    let searchDef = {

        page_row:'',
        page_current:'',
        page_total:''
    };
    export default{
        props:{
            pParams:Object,
            pQuery:Object,
        },
        components:{
            operateDetail,
            operateSave
        },
        data(){
            return{
                id:'',
                title:'',
                list:undefined,
                edit_group:{},
                search:{}
            }
        },
        computed:{
            no_return(){
                return this.pQuery&&this.pQuery.no_return||this.$route.query.no_return||false
            }
        },
        beforeMount(){
            this.$set(this, 'id',this.pParams&&this.pParams.id||this.$route.params.id);
            this.$set(this, 'title',this.pQuery&&this.pQuery.title||this.$route.query.title);
            this.searchReset();
        },
        mounted(){
            this.init();
        },
        methods:{
            searchReset(update,pageState){
                if(pageState){
                    this.$clientPage.def(this.search);
                    return false
                }
                const _p=this.$clientPage.getData(__page_key);
                if(_p){
                    this.$set(this,'search',_p);
                }else{
                    this.$set(this,'search',Object.assign({},searchDef));
                    this.$clientPage.def(this.search);
                }
                if(update){
                    this.init();
                }
            },
            searchPage(page){
                this.$clientPage.set(this.search,page);
            },
            searchChange(){
                this.$clientPage.def(this.search);
                this.init();
            },
            pageRowChange(num){
                if(num!= this.search.page_row){
                    this.$set(this.search,'page_row',num);
                    if(this.search.page_current == 1){
                        this.init();
                    }
                }
            },
            pageCurrentChange(current){
                if(current!= this.search.page_current){
                    this.$set(this.search,'page_current',current);
                    this.init();
                }
            },
            linkPageChange(name,params,query){
                this.$clientPage.setData(__page_key,Object.assign({},this.search));
                if(name){
                    this.$router.push({name:name,params:params,query:query})
                }
            },
            //------------------------------------------------------------------------
            async init(){
                let res = await serConference.listChild({
                    parent_id:this.id
                });
                if(res.code==1){
                    this.list = res.data||[];
                    this.edit_group = res.addtion_data&&res.addtion_data.button||{};
                    //this.searchPage(res.addtion_data&&res.addtion_data.page_info);
                }else{
                    this.list = [];
                    //this.searchReset(undefined,true);
                    this.$Message.error(res.message);
                }
                return true;
            },
            lookAtDetail(type,data){
                if(type=='customer'){
                    this.linkPageChange('customerConferChildList',{id:data.id},{title:data.title})
                }
            },
            initSubmit(state){
                if(state){
                    this.init()
                }
            },

            exportFile(){
                serCustomer.exportConferChildCustomerFile();
            }
        }
    }
</script>